#! /usr/bin/python3
# coding=utf-8
# @time: 2025/10/23 19:30
# @Author:鹤川
import os
import time

from selenium.webdriver.common.by import By

from common.conf_path import datas_path
from pages.basePage import BasePage


myPath=datas_path
# myPath = r'E:\Work\codings\python\2506project\WebAutoECShop\datas'

class MsgPage(BasePage):
    #属性
    etype=(By.XPATH,"//*[@name='msg_type' and @value=0]")
    etitle=(By.XPATH,"//input[@name='msg_title']")
    econtent=(By.XPATH,"//textarea[@name='msg_content']")
    eFile=(By.XPATH,"//*[@name='message_img']")
    ebut=(By.XPATH,"//input[@class='bnt_bonus']")
    eDel=(By.CSS_SELECTOR," div > div:nth-child(4) > a")
    eNUM=(By.CSS_SELECTOR,"#pager>.f_l>b")


    #方法
    def addMsg(self,msgT,msg,f):
        #上传文件地址拼接
        fileName = os.path.join(myPath, f)
        self.begin_num=self.getELeTxt(self.findEle(self.eNUM))
        self.eleClick(self.findEle(self.etype))  #点击类型
        time.sleep(0.5)
        self.inputText(self.findEle(self.etitle),msgT)  #输入主题
        time.sleep(0.5)
        self.inputText(self.findEle(self.econtent),msg)  #输入内容
        time.sleep(0.5)
        self.inputText(self.findEle(self.eFile),fileName) #文件上传
        time.sleep(1)
        self.eleClick(self.findEle(self.ebut))  #点击

    #删除
    def delMsg(self):
        """删除"""
        self.begin_num=self.getELeTxt(self.findEle(self.eNUM))
        self.eleClick(self.findEle(self.eDel))
        # time.sleep(1)
    def delMsgOk(self):
        """确认删除"""
        # 处理弹窗确认
        self.delMsg()
        alert = self.driver.switch_to.alert
        time.sleep(1)
        alert.accept()    # 确认删除
        end_num = self.getELeTxt(self.findEle(self.eNUM))  # 获取执行后的数量
        time.sleep(2)
        return self.begin_num, end_num
    def delError(self):
        """取消删除"""
        self.delMsg()
        alert = self.driver.switch_to.alert   # 处理弹窗确认
        time.sleep(1)
        alert.dismiss()   # 取消删除
        end_num = self.getELeTxt(self.findEle(self.eNUM))  # 获取没执行的数量
        return self.begin_num, end_num
    def addMSGok(self):
        #已经是ok的情况
        #获取执行后的数量
        end_num = self.getELeTxt(self.findEle(self.eNUM))
        return self.begin_num,end_num
    def addErrorNone(self):
        t=self.getAlertTxt()
        return t
